import JSEncrypt from 'jsencrypt/bin/jsencrypt.min'

// 密钥对生成 http://web.chacuo.net/netrsakeypair

const publicKey =
  'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALUmoWvULUmuIetMseXYSyecI26l31Gq\n' +
  'lXK7tpEbPG5uE/eO1XjouEAlbSWoBbzqnCJ9tfpfBTC15srNswWfFkECAwEAAQ=='

const privateKey =
  'MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAtSaha9QtSa4h60yx\n' +
  '5dhLJ5wjbqXfUaqVcru2kRs8bm4T947VeOi4QCVtJagFvOqcIn21+l8FMLXmys2z\n' +
  'BZ8WQQIDAQABAkEApyA3xtKe4Z4snvhIHER7udR8gAW6TY7yiEKUgbU+AKYxsh8T\n' +
  'DqgBMcOwXqp/2QRvUdvp80uuvJrWdujjJol8AQIhAOZ4kEBqJHKoQDycEFv2g6eD\n' +
  'AQBLuIiOanR89O/uE+QhAiEAyTeBIv/OxurdeHAKc/vxrlMicRYeNhyAlko1Tvf4\n' +
  '7iECIFDtwxGrc/MDG9Nspd31GVPoD6Dv9fOVttIC0uuxeTChAiAcoJTy0cotasTP\n' +
  'mcEi9zlPP+yqgicSM8Pnne8vqP/1gQIgRqV6Lr5rmbXhBC2NaJ9l+AVtWP4a5qZF\n' +
  'j0p6i4El6ic='

// 加密
export function encrypt (txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPublicKey(publicKey) // 设置公钥
  return encryptor.encrypt(txt) // 对数据进行加密
}

// 解密
export function decrypt (txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPrivateKey(privateKey) // 设置私钥
  return encryptor.decrypt(txt) // 对数据进行解密
}
